package indi.zhifa.recipe.bailan.framework.auth.dao;

import com.alibaba.fastjson2.JSONObject;
import indi.zhifa.recipe.bailan.framework.auth.entity.po.BaseRelUserRoleEntity;
import indi.zhifa.recipe.bailan.framework.auth.entity.po.BaseRoleEntity;
import indi.zhifa.recipe.bailan.framework.auth.entity.po.BaseUserEntity;
import indi.zhifa.recipe.bailan.framework.common.entity.exception.ServiceException;

import java.util.List;


public interface IBaseUserRelevantDao {
    BaseUserEntity user_generate();
    BaseUserEntity user_check(Long id);
    Long user_findByUserName(String pUserName);

    default BaseUserEntity user_check(String pUserName){
        Long id = user_findByUserName(pUserName);
        if(null == id){
            throw new ServiceException("没有找到名为"+pUserName+"的用户，或者您没有权限访问它");
        }
        return user_check(id);
    }

    default boolean user_existByName(String pUserName){
        Long id = user_findByUserName(pUserName);
        return null != id;
    }

    BaseUserEntity user_save(BaseUserEntity pBaseUserEntity);
    BaseUserEntity user_edit(Long pId, BaseUserEntity pBaseUserEntity);
    BaseUserEntity user_removeById(Long pId);

    List<BaseRoleEntity> role_list();

    Long role_findByCode(String pCode);

    BaseRoleEntity role_check(Long pId);

    default BaseRoleEntity role_check(String pCode){
        Long id = role_findByCode(pCode);
        if(null == id){
            throw new ServiceException("不存在code为"+pCode+"的角色，或者您没有权限访问它");
        }
        return role_check(id);
    }

    default boolean role_existByCode(String pCode){
        Long id = role_findByCode(pCode);
        return null != id;
    }

    BaseRoleEntity role_save(BaseRoleEntity pBaseRoleEntity);

    BaseRelUserRoleEntity relUserRole_generate();
    List<BaseRelUserRoleEntity> relUserRole_listByUserId(Long pUserId);

    boolean relUserRole_updateRoles(Long pUserId, List<BaseRelUserRoleEntity> relUserRoleEntityList);

    BaseUserEntity user_load(JSONObject pUserCfg);

    BaseRoleEntity role_load(JSONObject pRoleCfg);

}
